<template>
  <div class="login-page f-c a-c">
    <el-radio-group v-model="radio" class="radio" @change="changeType">
      <el-radio-button label="admin">管理员</el-radio-button>
      <el-radio-button label="teacher">教师</el-radio-button>
      <el-radio-button label="student">学生</el-radio-button>
    </el-radio-group>
    <div class="login-form">
      <div class="title">欢迎进入学生管理系统</div>
      <el-form>
        <el-form-item label="">
          <el-input v-model="ruleForm.username" clearable placeholder="账号" />
        </el-form-item>
        <el-form-item label="" style="margin-bottom: 0">
          <el-input v-model="ruleForm.password" clearable placeholder="密码" type="password" />
        </el-form-item>
        <el-form-item style="text-align: right" />
        <el-form-item>
          <el-button :disabled="isLogin" :loading="isLogin" type="primary" style="width: 100%" @click="login">{{ isLogin ? '登录中' : '登录' }}</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      radio: 'teacher',
      ruleForm: {
        username: 'teacher',
        password: '123456',
        type: 'teacher'
      },
      isLogin: false
    }
  },
  methods: {
    changeType(val) {
      if (val === 'admin') {
        this.$router.replace({
          path: '/login'
        })
      } else if (val === 'teacher') {
        this.$router.replace({
          path: '/login-teacher'
        })
      } else if (val === 'student') {
        this.$router.replace({
          path: '/login-student'
        })
      }
    },

    async login() {
      this.isLogin = true
      try {
        await this.$store.dispatch('user/login', { ...this.ruleForm })
        this.$router.replace({
          path: '/'
        })
      } catch (e) {
        this.isLogin = false
      }
    }
  }
}
</script>
<style scoped lang="scss">
.login-page {
  background-image: url("~@/assets/login-bg.png");
  background-size: 100% 100%;
  background-repeat: no-repeat;
  min-width: 1440px;
  min-height: 892px;
  height: 100%;
  width: 100%;
  position: relative;
  .radio {
    position: absolute;
    top: 50px;
    right: 50px;
    z-index: 99;
  }
  .login-title {
    width: 976px;
    height: 133px;
    font-size: 57px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    color: #FFFFFF;
    line-height: 77px;
    margin-top: 78px;
  }
  .login-form {
    margin-top: 178px;
    width: 413px;
    background: #FFFFFF;
    border-radius: 21px;
    padding: 40px;
    .title {
      color: #457EFF;
      font-size: 17px;
      line-height: 17px;
      position: relative;
      text-align: center;
      &::after {
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        bottom: -14px;
        width: 100px;
        background-color: #457EFF;
        height: 2px;
        display: inline-block;
        content: ' ';
      }
      margin-bottom: 43px;
    }

  }
}
</style>
